//
//  Ugc_Friends_TbvHeadFind_WX.m
//  ZITHER
//
//  Created by weixin on 2019/1/14.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "Ugc_Friends_TbvHeadFind_WX.h"
#import "Ugc_Find_VC_WX.h"

@implementation Ugc_Friends_TbvHeadFind_WX

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self setUI];
        [self setMasonry];
        [self loadData];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        self.userInteractionEnabled = YES;
        [self addGestureRecognizer:tap];
        [[tap rac_gestureSignal]subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            NSLog(@"跳转");
            Ugc_Find_VC_WX *vc = [[Ugc_Find_VC_WX alloc]init];
            [self.getNav pushViewController:vc animated:YES];
        }];
        
    }
    return self;
}

-(void)loadData{
    
    [[serviceDefualt loadRecommendUserlist:[RecommendUserlistModel class]]subscribeNext:^(ResponseData * x) {
        if (x.success) {
            self.model = [RecommendUserlistModel yy_modelWithDictionary: x.responseRawData];
        }else{
            [Tools showTips:x.errorInfo];
        }
        
    }];
}

-(void)setUI{
    
    [self addSubview:self.icon];
    [self addSubview:self.leb];
    [self addSubview:self.userImage1];
    [self addSubview:self.userImage2];
    [self addSubview:self.userImage3];
    
    UIView *viewLine = [[UIView alloc]initWithFrame:CGRectMake(0, 49, kScreenW, 1)];
    viewLine.backgroundColor = [UIColor colorWithHex:@"f5f5f5"];
    [self addSubview:viewLine];
    
}

-(void)setModel:(RecommendUserlistModel *)model{
    _model = model;
    for (int i = 0; i<model.data.count; i++) {
        if (i == 0 ) {
                [self.userImage1 sd_setImage:model.data[0].avatar];
            
        }else if (i == 1){
                [self.userImage2 sd_setImage:model.data[1].avatar];

        }else{
                [self.userImage3 sd_setImage:model.data[2].avatar];

        }
    }
    
//    for (RecommendUserlistModelSub *model1 in model.data) {
//        [self.userImage1 sd_setImage:model1.avatar];
//    }
//    [self.userImage1 sd_setImage:model.data[0].avatar];
//    [self.userImage2 sd_setImage:model.data[1].avatar];
//    [self.userImage3 sd_setImage:model.data[2].avatar];

}
-(void)setMasonry{
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.centerY.equalTo(self.mas_centerY).offset(0);
        make.width.height.mas_equalTo(15);
    }];
    
    [self.leb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.icon.mas_right).offset(5);
        make.centerY.equalTo(self.mas_centerY).offset(0);
        make.height.mas_equalTo(15);
    }];
    
    [self.userImage1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.userImage2.mas_left).offset(-15);
        make.centerY.equalTo(self.mas_centerY).offset(0);
        make.width.height.mas_equalTo(32);
    }];
    
    [self.userImage2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.userImage3.mas_left).offset(-15);
        make.centerY.equalTo(self.mas_centerY).offset(0);
        make.width.height.mas_equalTo(32);
    }];
    
    [self.userImage3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-15);
        make.centerY.equalTo(self.mas_centerY).offset(0);
        make.width.height.mas_equalTo(32);
    }];
    
    
    for (int i = 0; i<3; i++) {
        
        UIImageView * iamgeV = nil;
        if (i==0) {
            iamgeV = self.userImage1;
        }else if(i == 1){
            iamgeV = self.userImage2;
        }else{
            iamgeV = self.userImage3;
        }
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        [view setCornerRadiusWithRadius:16.5 isMasks:YES];
//        view.backgroundColor = [UIColor yellowColor];
        [view setBorderWithColor:baseColorTheme width:1];
        [self addSubview:view];
        [self bringSubviewToFront:iamgeV];
//        [UIView exchangeSubviewAtIndex:iamgeV withSubviewAtIndex:view];    //交换两个图层
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(iamgeV).offset(-1);
            make.right.bottom.equalTo(iamgeV).offset(1);

//            make.height.width.mas_equalTo(33);
            //            make.bottom.right.equalTo(self.userImage3).offset(5);
        }];
    
    }
    

    [self setNeedsLayout];
}

-(BaseLab *)leb{
    if (!_leb) {
        _leb = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 1, 1) text:@"发现" font:14 textColor:[UIColor colorWithHex:@"333333"] isBold:NO numberOfLines:1];
        _leb.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:15];
    }
    return _leb;
}


-(BaseImageV *)icon{
    if (!_icon) {
        _icon = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 1, 1) contentMode:2];
        _icon.image = [UIImage imageNamed:@"发现_icon"];
    }
    return _icon;
}

-(BaseImageV *)userImage1{
    if (!_userImage1) {
        _userImage1 = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 1, 1) contentMode:2];
        [_userImage1 setCornerRadiusWithRadius:16 isMasks:YES];
    }
    return _userImage1;
}

-(BaseImageV *)userImage2{
    if (!_userImage2) {
        _userImage2 = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 1, 1) contentMode:2];
        [_userImage2 setCornerRadiusWithRadius:16 isMasks:YES];
    }
    return _userImage2;
}

-(BaseImageV *)userImage3{
    if (!_userImage3) {
        _userImage3 = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 1, 1) contentMode:2];
        [_userImage3 setCornerRadiusWithRadius:16 isMasks:YES];
     
        
    }
    return _userImage3;
}

@end
